package com.example.wedding_mq.listener;

import com.zpp.wedding_mq.service.ICollectService;
import com.zpp.wedding_mq.service.IUserService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.zpp.wedding_admin.utils.RabbitConstants.*;

@Component
public class CollectListener {
    @Autowired
    private IUserService userService;

    @Autowired
    private ICollectService collectService;

    @RabbitListener(queues = QUEUE_COLLECT_ADD)
    public void listenerGoodAdd(String[] ids) {
        String id = ids[0];
        String userId = ids[1];
        collectService.collectAdd(id, userId);
        userService.collectAdd(userId);
    }

    @RabbitListener(queues = QUEUE_COLLECT_SUBTRACT)
    public void listenerGoodSubtract(String[] ids) {
        String id = ids[0];
        String userId = ids[1];
        userService.collectSubtract(userId);
        collectService.collectSubtract(id, userId);
    }
}
